import { FileTextTwoTone } from '@ant-design/icons-vue'

/**
 * todo highlight 【请务必确保路由的name唯一】
 * 菜单路由
 * path ==> 路由路径
 * name ==> 路由名称
 * component ==> 路由组件
 * redirect ==> 路由重定向
 * meta ==> 路由元信息
 * meta.isHide ==> 如果“isHide:true”不会显示在侧边栏中（默认值为false）
 * meta.keepAlive ==> 设为true 缓存
 * meta.title ==> 路由标题
 * meta.icon ==> 菜单icon
 * meta.super ==> antdv menu组件openKeys所需的数据，用于控制展开菜单
 * meta.activeMenu ==> 详情页的时候可以自定义设置菜单高亮，默认高亮当前路由的name属性
 */

const menuRoutes = [
  {
    path: '/task-manage',
    name: 'task-manage',
    meta: {
      title: '宣讲任务管理',
      layout: 'basic',
      keepAlive: false,
      icon: FileTextTwoTone
    },
    redirect: (to: any) => {
      return {
        name: 'task-list'
      }
    },
    children: [
      {
        path: 'task-list',
        name: 'task-list',
        meta: {
          title: '宣讲任务管理',
          layout: 'basic',
          keepAlive: true,
          icon: FileTextTwoTone
        },
        component: () => import('@/views/page1/list/index.vue')
      },
      {
        path: 'task-detail',
        name: 'task-detail',
        meta: {
          title: '宣讲任务详情',
          layout: 'basic',
          keepAlive: false,
          icon: FileTextTwoTone,
          isHide: true,
          activeMenu: 'task-list'
        },
        component: () => import('@/views/page1/detail/index.vue')
      }
    ]
  }
]

/**
 * 给路由添加super
 */
function routesAddSuper(routes: any[], superName?: string[] | string) {
  routes.forEach((route) => {
    if (!route.meta) {
      route.meta = {}
    }
    if (superName) {
      if (Array.isArray(superName)) {
        if (Array.isArray(route.meta.super)) {
          route.meta.super = route.meta.super.concat(superName)
        } else {
          route.meta.super = superName
        }
      } else {
        if (Array.isArray(route.meta.super)) {
          route.meta.super.push(superName)
        } else {
          route.meta.super = [superName]
        }
      }
    }
    if (route?.children?.length) {
      let _superNames = []
      if (route?.meta?.super) {
        _superNames = [...route.meta.super, route.name]
      } else {
        _superNames.push(route.name)
      }
      routesAddSuper(route.children, _superNames)
    }
  })
}

// 给路由信息添加super字段，该字段的作用为为antdv menu组件的openkey提供值
routesAddSuper(menuRoutes)

export { menuRoutes }
